﻿Public Class frmTiepNhanKhachHang

    Private Sub frmTiepNhanKhachHang_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LoadDanhSachLenLuoi()
    End Sub
    Public Sub LoadDanhSachLenLuoi()
        dgvDanhSachKhachHang.DataSource = KhachHangDAO.selectall()
    End Sub

    Private Sub dgvDanhSachKhachHang_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgvDanhSachKhachHang.SelectionChanged
        If dgvDanhSachKhachHang.SelectedRows.Count > 0 Then
            txtMaKhachHang.Text = dgvDanhSachKhachHang.SelectedRows(0).Cells(0).Value.ToString()
            txtTenKhachHang.Text = dgvDanhSachKhachHang.SelectedRows(0).Cells(1).Value.ToString()
            txtDiemTichLuy.Text = dgvDanhSachKhachHang.SelectedRows(0).Cells(3).Value.ToString()
            txtDienThoai.Text = dgvDanhSachKhachHang.SelectedRows(0).Cells(4).Value.ToString()
            txtTienNo.Text = dgvDanhSachKhachHang.SelectedRows(0).Cells(2).Value.ToString()
        End If
    End Sub

    Private Sub btnThem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThem.Click
        Dim kh As New KhachHangDTO
        kh.MaKhachHang = txtMaKhachHang.Text
        kh.TenKhachHang = txtTenKhachHang.Text
        kh.TienNoKhachHang = txtTienNo.Text
        kh.DienThoai = txtDienThoai.Text
        kh.DiemTichLuy = txtDiemTichLuy.Text
        KhachHangDAO.insert(kh)
        LoadDanhSachLenLuoi()
    End Sub
   
    Private Sub BtnXoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnXoa.Click
        Dim kh As String
        kh = txtMaKhachHang.Text
        KhachHangDAO.delete(kh)
        LoadDanhSachLenLuoi()
    End Sub

    Private Sub btnSua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSua.Click
        Dim kh As KhachHangDTO = New KhachHangDTO
        kh.MaKhachHang = txtMaKhachHang.Text
        kh.DienThoai = txtDienThoai.Text
        kh.DiemTichLuy = txtDiemTichLuy.Text
        kh.TenKhachHang = txtTenKhachHang.Text
        kh.TienNoKhachHang = txtTienNo.Text

        KhachHangDAO.Update(kh)
        LoadDanhSachLenLuoi()
    End Sub
End Class